package com.chencong.online.function;

import org.apache.flink.api.common.functions.AggregateFunction;
import org.apache.flink.api.java.tuple.Tuple2;

/**
 * @program: user-behavior-analysis-online
 * @ClassName PageViewCountAggFunc
 * @description:PV分组聚合(累加窗口内相同key的数据)
 * @author: chencong
 * @create: 2021-12-28 11:06
 **/
public class PageViewCountAggFunc implements AggregateFunction<Tuple2<Integer, Long>, Long, Long> {

    @Override
    public Long createAccumulator() {
        return 0L;
    }

    @Override
    public Long add(Tuple2<Integer, Long> value, Long accumulator) {
        return accumulator + 1L;
    }


    @Override
    public Long getResult(Long accumulator) {
        return accumulator;
    }

    @Override
    public Long merge(Long a, Long b) {
        return a + b;
    }
}
